from django.shortcuts import render, HttpResponse
from app import models


# Create your views here.

def docker(request):
    return HttpResponse('ok')


# def db(request):
#
#     # 向数据表中存条数据
#     # 写到哪个库中了？默认情况下写到default
#     res = models.User.objects.using('default').create(name='randy1', age=18)
#
#     print('default', res.name)
#     print('default', res.age)
#
#     # 读第一条数据，默认从哪读？default
#     ret = models.User.objects.all().first()
#
#     # 指定去从库读？在queryset对象后加个.using('db1')
#     ret = models.User.objects.all().using('db').first()
#     print(ret)
#     print('db', ret.name)
#     print('db', ret.age)
#     return HttpResponse('db ok')
def db(request):
    # 向数据表中存条数据
    # 写到哪个库中了 默认写到default
    res = models.User.objects.create(name='randy', age=18)

    print('default', res.name)
    print('default', res.age)

    print('*' * 100)

    # 去从库读数据
    ret = models.User.objects.all().first()
    print(ret)
    print('db_mysql', ret.name)
    print('db_mysql', ret.age)
    return HttpResponse('db ok')
